package com.zcf.vo.in;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zcf.utils.HttpRequest;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author Stephen May
 * @date 2019/02/19
 */
@RestController
@CrossOrigin
@ResponseBody
public class PersonageInviteController {
	/**
	 * 高德逆地理
	 * 
	 * @param args123.311634,41.44476
	 */
	public static void main(String[] args) {
		String s = HttpRequest.sendGet("https://restapi.amap.com/v3/geocode/regeo", "location=" + "123.311634" + ","
				+ "41.44476"
				+ "&radius=1000&extensions=base&batch=false&roadlevel=1&sig=17851026a78538a5c0ef6fb7e39078f0&key=04fae9b07d8abd27177207d1abc8bca6");
		JSONObject jsonObject10 = JSONObject.parseObject(s).getJSONObject("regeocode")
				.getJSONObject("addressComponent");
		JSONObject jsonObject1 = JSONObject.parseObject(s).getJSONObject("regeocode").getJSONObject("addressComponent")
				.getJSONObject("streetNumber");
		String city1 = jsonObject10.getString("city");
		String province = jsonObject10.getString("province");
		String district = jsonObject10.getString("district");
		String township = jsonObject10.getString("township");
		String street = jsonObject1.getString("street");
		System.err.println(province);
		System.err.println(city1);
		System.err.println(district);
		System.err.println(township);
		System.err.println(street);
		System.err.println(jsonObject10);
		String address = city1 + province + district + township + street;
		System.err.println(address);
	}

	public String Geocoding(String latitude, String longitude) {
		String s = HttpRequest.sendGet("https://restapi.amap.com/v3/geocode/regeo", "location=" + longitude + ","
				+ latitude
				+ "&radius=1000&extensions=base&batch=false&roadlevel=1&sig=17851026a78538a5c0ef6fb7e39078f0&key=04fae9b07d8abd27177207d1abc8bca6");
		JSONObject jsonObject10 = JSONObject.parseObject(s).getJSONObject("regeocode")
				.getJSONObject("addressComponent");
		JSONObject jsonObject1 = JSONObject.parseObject(s).getJSONObject("regeocode").getJSONObject("addressComponent")
				.getJSONObject("streetNumber");
		String city1 = jsonObject10.getString("city");
		String province = jsonObject10.getString("province");
		String district = jsonObject10.getString("district");
		String township = jsonObject10.getString("township");
		String street = jsonObject1.getString("street");
		String address = city1 + province + district + township + street;
//		System.err.println(province);
//		System.err.println(city1);
//		System.err.println(district);
//		System.err.println(township);
//		System.err.println(street);
//		System.err.println(jsonObject10);
//		System.err.println(address);
		return address;
	}
	public String GeocoDistrict(String latitude, String longitude) {
		String s = HttpRequest.sendGet("https://restapi.amap.com/v3/geocode/regeo", "location=" + longitude + ","
				+ latitude
				+ "&radius=1000&extensions=base&batch=false&roadlevel=1&sig=17851026a78538a5c0ef6fb7e39078f0&key=04fae9b07d8abd27177207d1abc8bca6");
		JSONObject jsonObject10 = JSONObject.parseObject(s).getJSONObject("regeocode")
				.getJSONObject("addressComponent");
		JSONObject jsonObject1 = JSONObject.parseObject(s).getJSONObject("regeocode").getJSONObject("addressComponent")
				.getJSONObject("streetNumber");
		String city1 = jsonObject10.getString("city");
		String province = jsonObject10.getString("province");
		String district = jsonObject10.getString("district");
		String township = jsonObject10.getString("township");
		String street = jsonObject1.getString("street");
		String address = city1 + province + district + township + street;
//		System.err.println(province);
//		System.err.println(city1);
//		System.err.println(district);
//		System.err.println(township);
//		System.err.println(street);
//		System.err.println(jsonObject10);
//		System.err.println(address);
		return district;
	}
}
